home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / EmacsFrame.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-26  |  23.6 KB  |  667 lines

  1. /* The emacs frame widget.
  2.    Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: Not in FSF. */
  21.  
  22. /* #### Note to potential hackers: Don't mess with this unless you're
  23.    sure you know what you're doing!  Xt is a lot more subtle than
  24.    you may think. */
  25.  
  26. #include <config.h>
  27. #include "lisp.h"
  28.  
  29. #include "device-x.h"
  30. #include "frame-x.h"
  31. #include "glyphs-x.h"
  32. #include "objects-x.h"
  33. #include <X11/Shell.h>
  34. #include "EmacsFrameP.h"
  35. #include "EmacsManager.h"    /* for EmacsManagerChangeSize */
  36. #include "xmu.h"
  37.  
  38. #include "faces.h"
  39. #include "toolbar.h"
  40. #include "redisplay.h"
  41.  
  42. static void EmacsFrameClassInitialize (void);
  43. static void EmacsFrameInitialize (Widget, Widget, ArgList, Cardinal *);
  44. static void EmacsFrameRealize (Widget, XtValueMask*, XSetWindowAttributes*);
  45. static void EmacsFrameResize (Widget widget);
  46. static Boolean EmacsFrameSetValues (Widget, Widget, Widget,
  47.                      ArgList, Cardinal *);
  48. static XtGeometryResult EmacsFrameQueryGeometry (Widget, XtWidgetGeometry*,
  49.                           XtWidgetGeometry*);
  50.  
  51. extern void
  52. emacs_Xt_mapping_action (Widget w, XMappingEvent* event);
  53.  
  54. #undef XtOffset
  55. #define XtOffset(p_type,field) \
  56.     ((Cardinal) (((char *) (&(((p_type)0)->field))) - ((char *)0)))
  57. #define offset(field) XtOffset(EmacsFrame, emacs_frame.field)
  58.  
  59. static XtResource resources[] = {
  60.   {XtNgeometry, XtCGeometry, XtRString, sizeof(String),
  61.      offset (geometry), XtRString, (XtPointer) 0},
  62.   {XtNiconic, XtCIconic, XtRBoolean, sizeof(Boolean),
  63.      offset (iconic), XtRImmediate, (XtPointer) False},
  64.  
  65.   {XtNemacsFrame, XtCEmacsFrame, XtRPointer, sizeof (XtPointer),
  66.      offset (frame), XtRImmediate, 0},
  67.   {XtNmenubar, XtCMenubar, XtRBoolean, sizeof (Boolean),
  68.      offset (menubar_p), XtRImmediate, (XtPointer)1},
  69.   {XtNinitiallyUnmapped, XtCInitiallyUnmapped, XtRBoolean, sizeof (Boolean),
  70.      offset (initially_unmapped), XtRImmediate, (XtPointer)0},
  71.   {XtNminibuffer, XtCMinibuffer, XtRInt, sizeof (int),
  72.      offset (minibuffer), XtRImmediate, (XtPointer)0},
  73.   {XtNunsplittable, XtCUnsplittable, XtRBoolean, sizeof (Boolean),
  74.      offset (unsplittable), XtRImmediate, (XtPointer)0},
  75.   {XtNinternalBorderWidth, XtCInternalBorderWidth, XtRInt, sizeof (int),
  76.      offset (internal_border_width), XtRImmediate, (XtPointer)4},
  77.   {XtNscrollBarWidth, XtCScrollBarWidth, XtRInt, sizeof (int),
  78.      offset (scrollbar_width), XtRImmediate, (XtPointer)-1},
  79.   {XtNscrollBarHeight, XtCScrollBarHeight, XtRInt, sizeof (int),
  80.      offset (scrollbar_height), XtRImmediate, (XtPointer)-1},
  81.   {XtNtopToolBarHeight, XtCTopToolBarHeight, XtRInt, sizeof (int),
  82.      offset (top_toolbar_height), XtRImmediate, (XtPointer)-1},
  83.   {XtNbottomToolBarHeight, XtCBottomToolBarHeight, XtRInt, sizeof (int),
  84.      offset (bottom_toolbar_height), XtRImmediate, (XtPointer)-1},
  85.   {XtNleftToolBarWidth, XtCLeftToolBarWidth, XtRInt, sizeof (int),
  86.      offset (left_toolbar_width), XtRImmediate, (XtPointer)-1},
  87.   {XtNrightToolBarWidth, XtCRightToolBarWidth, XtRInt, sizeof (int),
  88.      offset (right_toolbar_width), XtRImmediate, (XtPointer)-1},
  89.   {XtNtopToolBarShadowColor, XtCTopToolBarShadowColor, XtRPixel, sizeof(Pixel),
  90.      offset(top_toolbar_shadow_pixel), XtRImmediate, (XtPointer)-1},
  91.   {XtNbottomToolBarShadowColor, XtCBottomToolBarShadowColor, XtRPixel,
  92.      sizeof(Pixel), offset(bottom_toolbar_shadow_pixel), XtRImmediate,
  93.      (XtPointer)-1},
  94.   {XtNbackgroundToolBarColor, XtCBackgroundToolBarColor, XtRPixel,
  95.      sizeof(Pixel), offset(background_toolbar_pixel), XtRImmediate,
  96.      (XtPointer)-1},
  97.   {XtNtopToolBarShadowPixmap, XtCTopToolBarShadowPixmap, XtRPixmap,
  98.      sizeof (Pixmap), offset(top_toolbar_shadow_pixmap), XtRImmediate,
  99.      (XtPointer)None},
  100.   {XtNbottomToolBarShadowPixmap, XtCBottomToolBarShadowPixmap, XtRPixmap,
  101.      sizeof (Pixmap), offset(bottom_toolbar_shadow_pixmap), XtRImmediate,
  102.      (XtPointer)None},
  103.   {XtNtoolBarShadowThickness, XtCToolBarShadowThickness, XtRDimension,
  104.      sizeof (Dimension), offset (toolbar_shadow_thickness), XtRImmediate,
  105.      (XtPointer)-1},
  106.   { XtNscrollBarPlacement, XtCScrollBarPlacement, XtRScrollBarPlacement,
  107.       sizeof(unsigned char), offset(scrollbar_placement), XtRImmediate,
  108. #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
  109.       (XtPointer) XtBOTTOM_RIGHT
  110. #else
  111.       (XtPointer) XtBOTTOM_LEFT
  112. #endif
  113.   },
  114.   {XtNinterline, XtCInterline, XtRInt, sizeof (int),
  115.      offset (interline), XtRImmediate, (XtPointer)0},
  116.   {
  117. #ifdef I18N4
  118.     XtNfontSet, XtCFontSet, XtRFontSet,    sizeof(XFontSet),
  119. #else
  120.     XtNfont,    XtCFont,    XtRFontStruct, sizeof(XFontStruct *),
  121. #endif
  122.     offset(font), XtRImmediate, (XtPointer)0
  123.   },
  124.   {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  125.      offset(foreground_pixel), XtRString, "XtDefaultForeground"},
  126.   {XtNcursorColor, XtCForeground, XtRPixel, sizeof(Pixel),
  127.      offset(cursor_color), XtRString, "XtDefaultForeground"},
  128.   {XtNbarCursor, XtCBarCursor, XtRBoolean, sizeof (Boolean),
  129.      offset (bar_cursor), XtRImmediate, (XtPointer)0},
  130.   {XtNvisualBell, XtCVisualBell, XtRBoolean, sizeof (Boolean),
  131.      offset (visual_bell), XtRImmediate, (XtPointer)0},
  132.   {XtNbellVolume, XtCBellVolume, XtRInt, sizeof (int),
  133.      offset (bell_volume), XtRImmediate, (XtPointer)0},
  134.   {XtNuseBackingStore, XtCUseBackingStore, XtRBoolean, sizeof (Boolean),
  135.      offset (use_backing_store), XtRImmediate, (XtPointer)0},
  136.   {XtNpreferredWidth, XtCPreferredWidth, XtRDimension, sizeof (Dimension),
  137.      offset (preferred_width), XtRImmediate, (XtPointer)0},
  138.   {XtNpreferredHeight, XtCPreferredHeight, XtRDimension, sizeof (Dimension),
  139.      offset (preferred_height), XtRImmediate, (XtPointer)0},
  140. };
  141.  
  142. #undef offset
  143.  
  144. /* Xt is stupid and dumb.
  145.    Xt is stupid and dumb.
  146.    Xt is stupid and dumb. */
  147.  
  148. static XtActionsRec
  149. emacsFrameActionsTable [] = {
  150.   {"mapping",  (XtActionProc) emacs_Xt_mapping_action},
  151. };
  152.  
  153. static char
  154. emacsFrameTranslations [] = "\
  155. <Mapping>: mapping()\n\
  156. ";
  157.  
  158. /* If we're running under Motif, make this widget a subclass
  159.    of XmPrimitive.  It's not clear this is necessary, but it
  160.    may make focus behavior work better. */
  161.  
  162. EmacsFrameClassRec emacsFrameClassRec = {
  163.     { /* core fields */
  164. #ifdef LWLIB_USES_MOTIF
  165.     /* superclass        */    (WidgetClass) &xmPrimitiveClassRec,
  166. #else
  167.     /* superclass        */    &widgetClassRec,
  168. #endif
  169.     /* class_name        */    "EmacsFrame",
  170.     /* widget_size        */    sizeof(EmacsFrameRec),
  171.     /* class_initialize        */    EmacsFrameClassInitialize,
  172.     /* class_part_initialize    */    0,
  173.     /* class_inited        */    FALSE,
  174.     /* initialize        */    EmacsFrameInitialize,
  175.     /* initialize_hook        */    0,
  176.     /* realize            */    EmacsFrameRealize,
  177.     /* actions            */    emacsFrameActionsTable,
  178.     /* num_actions        */    XtNumber (emacsFrameActionsTable),
  179.     /* resources        */    resources,
  180.     /* resource_count        */    XtNumber(resources),
  181.     /* xrm_class        */    NULLQUARK,
  182.     /* compress_motion        */    TRUE,
  183.     /* compress_exposure    */    TRUE,
  184.     /* compress_enterleave    */    TRUE,
  185.     /* visible_interest        */    FALSE,
  186.     /* destroy            */    NULL,
  187.     /* resize            */    EmacsFrameResize,
  188.     /* expose            */    XtInheritExpose,
  189.     /* set_values        */    EmacsFrameSetValues,
  190.     /* set_values_hook        */    0,
  191.     /* set_values_almost    */    XtInheritSetValuesAlmost,
  192.     /* get_values_hook        */    0,
  193.     /* accept_focus        */    XtInheritAcceptFocus,
  194.     /* version            */    XtVersion,
  195.     /* callback_private        */    0,
  196.     /* tm_table            */    emacsFrameTranslations,
  197.     /* query_geometry        */    EmacsFrameQueryGeometry,
  198.     /* display_accelerator    */    XtInheritDisplayAccelerator,
  199.     /* extension        */    0
  200.     },
  201. #ifdef LWLIB_USES_MOTIF
  202.     {    /* XmPrimitiveClassPart
  203.      */
  204.       (XtWidgetProc) _XtInherit,    /* border_highlight */
  205.       (XtWidgetProc) _XtInherit,    /* border_unhighlight */
  206.       /* Setting the following to NULL causes PrimitiveInitialize()
  207.      not to add traversal (TAB etc. to switch focus) and
  208.      focus-in/out (border highlight/unhighlight) translations.
  209.      If you want those translations, use the value XtInheritTranslations
  210.      instead.  Doing this, however, will interfere with Emacs
  211.      focus handling (which highlights/unhighlights the text cursor),
  212.      and will lead to strange display results around the border of the
  213.      widget. */
  214.       NULL,                /* translations */
  215.       NULL,                /* arm_and_activate */
  216.       NULL,                /* get resources */
  217.       0,                /* num get_resources */
  218.       NULL,                /* extension */
  219.     },
  220. #endif /* LWLIB_USES_MOTIF */
  221.     {
  222.       0
  223.     }
  224. };
  225. WidgetClass emacsFrameClass = (WidgetClass) &emacsFrameClassRec;
  226.  
  227. static void
  228. get_default_char_pixel_size (EmacsFrame ew, Dimension *pixel_width,
  229.                  Dimension *pixel_height)
  230. {
  231.   struct Lisp_Font_Instance *xfont;
  232.   Lisp_Object frame, font;
  233.  
  234.   XSETFRAME (frame, ew->emacs_frame.frame);
  235.   font = FACE_FONT (Vdefault_face, frame);
  236.  
  237.   xfont = XFONT_INSTANCE (font);
  238.   assert (EQ (FRAME_DEVICE (ew->emacs_frame.frame), xfont->device));
  239.   assert (FONT_INSTANCE_WIDTH (xfont));
  240.   assert (FONT_INSTANCE_HEIGHT (xfont));
  241.  
  242.   *pixel_height = FONT_INSTANCE_HEIGHT (xfont);
  243.   *pixel_width = FONT_INSTANCE_WIDTH (xfont);
  244.  
  245.   /* there used to be code here that calculated the width of the 'n' 
  246.      character.  Look at Fmake_font() for where this is done now. */
  247. }
  248.  
  249. static void
  250. conversion_internal (EmacsFrame ew, int pixel_to_char,
  251.              Dimension *pixel_width, Dimension *pixel_height,
  252.              int *char_width, int *char_height)
  253. {
  254.   Dimension cpw;
  255.   Dimension cph;
  256.   Dimension egw;
  257.   Dimension obw, obh, bdr;
  258.   struct frame *f;
  259.   Lisp_Object frame, window;
  260.  
  261.   get_default_char_pixel_size (ew, &cpw, &cph);
  262.   f = ew->emacs_frame.frame;
  263.   XSETFRAME (frame, f);
  264.   window = FRAME_SELECTED_WINDOW (f);
  265.  
  266.   egw = max (glyph_width (Vcontinuation_glyph, DEFAULT_INDEX, 1, window),
  267.          glyph_width (Vtruncation_glyph, DEFAULT_INDEX, 1, window));
  268.   egw = max (egw, cpw);
  269.   bdr = 2 * ew->emacs_frame.internal_border_width;
  270.   obw = FRAME_SCROLLBAR_WIDTH (f) + FRAME_LEFT_TOOLBAR_WIDTH (f) +
  271.     FRAME_RIGHT_TOOLBAR_WIDTH (f);
  272.   obh = FRAME_SCROLLBAR_HEIGHT (f) + FRAME_TOP_TOOLBAR_HEIGHT (f) +
  273.     FRAME_BOTTOM_TOOLBAR_HEIGHT (f);
  274.  
  275.   if (pixel_to_char)
  276.     {
  277.       *char_width = 1 + (int) ((*pixel_width - egw) - bdr - obw) / (int) cpw;
  278.       *char_height = (int) (*pixel_height - bdr - obh) / (int) cph;
  279.     }
  280.   else
  281.     {
  282.       *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw;
  283.       *pixel_height = *char_height * cph + bdr + obh;
  284.     }
  285. }
  286.              
  287. /* This takes the size in pixels of the text area, and returns the number
  288.    of characters that will fit there, taking into account the internal
  289.    border width, and the pixel width of the line terminator glyphs (which
  290.    always count as one "character" wide, even if they are not the same size
  291.    as the default character size of the default font).  The frame scrollbar
  292.    width and left and right toolbar widths are also subtracted out of the
  293.    available width.  The frame scrollbar height and top and bottom toolbar
  294.    heights are subtracted out of the available height.
  295.  
  296.    Therefore the result is not necessarily a multiple of anything in
  297.    particular.  */
  298. static void
  299. pixel_to_char_size (EmacsFrame ew,
  300.             Dimension pixel_width, Dimension pixel_height,
  301.             int *char_width, int *char_height)
  302. {
  303.   conversion_internal (ew, 1, &pixel_width, &pixel_height, char_width,
  304.                char_height);
  305. }
  306.  
  307. /* Given a character size, this returns the minimum number of pixels
  308.    necessary to display that many characters, taking into account the
  309.    internal border width, scrollbar height and width, toolbar heights and
  310.    widths and the size of the line terminator glyphs (assuming the line
  311.    terminators take up exactly one character position).
  312.  
  313.    Therefore the result is not necessarily a multiple of anything in
  314.    particular.  */
  315. static void
  316. char_to_pixel_size (EmacsFrame ew, int char_width, int char_height,
  317.             Dimension *pixel_width, Dimension *pixel_height)
  318. {
  319.   conversion_internal (ew, 0, pixel_width, pixel_height, &char_width,
  320.                &char_height);
  321. }
  322.  
  323. /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary
  324.    to display the same number of characters as are displayable now.
  325.  */
  326. static void
  327. round_size_to_char (EmacsFrame ew,
  328.             Dimension in_width, Dimension in_height,
  329.             Dimension *out_width, Dimension *out_height)
  330. {
  331.   int char_width;
  332.   int char_height;
  333.   pixel_to_char_size (ew, in_width, in_height, &char_width, &char_height);
  334.   char_to_pixel_size (ew, char_width, char_height, out_width, out_height);
  335. }
  336.  
  337. static void
  338. update_various_frame_slots (EmacsFrame ew)
  339. {
  340.   ew->emacs_frame.frame->pixheight = ew->core.height;
  341.   ew->emacs_frame.frame->pixwidth = ew->core.width;
  342.   ew->emacs_frame.frame->internal_border_width =
  343.     ew->emacs_frame.internal_border_width;
  344. }
  345.  
  346. static void 
  347. EmacsFrameInitialize (Widget request, Widget new,
  348.                ArgList dum1, Cardinal *dum2)
  349. {
  350.   EmacsFrame ew = (EmacsFrame)new;
  351.   struct frame *f = ew->emacs_frame.frame;
  352.  
  353.   if (!f)
  354.     fatal ("can't create an emacs frame widget without a frame.");
  355. }
  356.  
  357. void emacs_Xt_event_handler (Widget wid /* unused */,
  358.                  XtPointer closure /* unused */,
  359.                  XEvent *event,
  360.                  Boolean *continue_to_dispatch /* unused */);
  361.  
  362. static void
  363. EmacsFrameRealize (Widget widget, XtValueMask *mask,
  364.            XSetWindowAttributes *attrs)
  365. {
  366.   EmacsFrame ew = (EmacsFrame) widget;
  367.   struct frame *f = ew->emacs_frame.frame;
  368.   Widget shell_widget = FRAME_X_SHELL_WIDGET (f);
  369.  
  370.   attrs->event_mask = (ExposureMask | StructureNotifyMask |
  371.                VisibilityChangeMask | PropertyChangeMask |
  372.                StructureNotifyMask | SubstructureNotifyMask |
  373.                SubstructureRedirectMask | KeyPressMask |
  374.                KeyReleaseMask |
  375.                ButtonPressMask | ButtonReleaseMask |
  376.                FocusChangeMask | PointerMotionHintMask |
  377.                PointerMotionMask | LeaveWindowMask |
  378.                EnterWindowMask);
  379.  
  380. #ifdef I18N4
  381.   /* Make sure that events wanted by the input method are selected. */
  382.   attrs->event_mask |= input_method_event_mask;
  383. #endif
  384.  
  385.   *mask |= CWEventMask;
  386.  
  387.   if (ew->emacs_frame.use_backing_store)
  388.     {
  389.       attrs->backing_store = Always;
  390.       *mask |= CWBackingStore;
  391.     }
  392.   XtCreateWindow (widget, InputOutput, (Visual *)CopyFromParent, *mask,
  393.           attrs);
  394.  
  395.   /* snarf the events we want. */
  396.   XtInsertEventHandler (widget, attrs->event_mask, TRUE,
  397.             emacs_Xt_event_handler, NULL, XtListHead);
  398.   /* some events (e.g. map-notify and WM_DELETE_WINDOW) get sent
  399.      directly to the shell, and the above event handler won't see
  400.      them.  So add a handler to get them.  These events don't
  401.      propagate, so there's no danger of them being seen twice. */
  402.   XtInsertEventHandler (shell_widget,
  403.             EnterWindowMask | LeaveWindowMask |
  404.             VisibilityChangeMask | StructureNotifyMask |
  405.             KeyPressMask,
  406.             TRUE, emacs_Xt_event_handler, NULL, XtListHead);
  407.  
  408. #ifdef EXTERNAL_WIDGET
  409.   /* #### Not sure if this special case is necessary */
  410.   if (!FRAME_X_EXTERNAL_WINDOW_P (f))
  411. #endif
  412.     /* This is necessary under Motif in order to make it possible to click in
  413.        a buffer and move focus out of a dialog box or control panel and back
  414.        into emacs-land; also necessary so that you can still type chars
  415.        if the cursor is over the menubar or scrollbar. */
  416.     lw_set_keyboard_focus (shell_widget, FRAME_X_TEXT_WIDGET (f));
  417. }
  418.  
  419. /* DO NOT CALL THIS FUNCTION!  Only Xt is supposed to do this. */
  420.  
  421. static void
  422. EmacsFrameResize (Widget widget)
  423. {
  424.   EmacsFrame ew = (EmacsFrame)widget;
  425.   struct frame *f = ew->emacs_frame.frame;
  426.   int columns;
  427.   int rows;
  428.   XtWidgetGeometry req, repl;
  429.   
  430.   pixel_to_char_size (ew, ew->core.width, ew->core.height, &columns, &rows);
  431.   update_various_frame_slots (ew);
  432.   change_frame_size (f, rows, columns, 0, 0);
  433.  
  434.   /* Now we tell the EmacsShell that we've changed the size of the non-fixed
  435.      portion of the frame.  Note that, if we the resize occurred as a result
  436.      of EmacsFrameSetCharSize(), this information will be stored twice.
  437.      This is not a big deal, as storing this information doesn't actually
  438.      do anything until the next resize. */
  439.   if (FRAME_X_TOP_LEVEL_FRAME_P (f))
  440.     x_wm_set_variable_size (FRAME_X_SHELL_WIDGET (f), columns, rows);
  441.  
  442.   /* Kick the manager so that it knows we've changed size. */
  443.   req.request_mode = 0;
  444.   XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
  445.   EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
  446.               repl.height);
  447. }
  448.  
  449. static Boolean
  450. EmacsFrameSetValues (Widget cur_widget, Widget req_widget, Widget new_widget,
  451.               ArgList dum1, Cardinal *dum2)
  452. {
  453.   EmacsFrame cur = (EmacsFrame) cur_widget;
  454.   EmacsFrame new = (EmacsFrame) new_widget;
  455.   Lisp_Object frame = Qnil;
  456.  
  457.   XSETFRAME (frame, new->emacs_frame.frame);
  458.   in_resource_setting++;
  459.   /* This function does not need to do much.  Pretty much everything
  460.      interesting will get done in the resize method, which will
  461.      (if necessary) get called by Xt when this function returns
  462.      (see below).
  463.    */
  464.  
  465.   /* #### This function will not work if it is not called from
  466.      update_EmacsFrame(), called from SET_FACE_PROPERTY().
  467.      The code located there should be moved inside of here instead,
  468.      so that things work if either SET_FACE_PROPERTY() is
  469.      called or XtSetValues() is called.
  470.      */
  471.  
  472.   if (cur->emacs_frame.iconic != new->emacs_frame.iconic &&
  473.       FRAME_X_TOP_LEVEL_FRAME_P (new->emacs_frame.frame))
  474.     x_wm_set_shell_iconic_p (FRAME_X_SHELL_WIDGET (new->emacs_frame.frame),
  475.                  new->emacs_frame.iconic);
  476.  
  477.   if (!in_specifier_change_function)
  478.     {
  479.       /* If we got here, then we were likely called as a result of
  480.      the EditRes protocol, so go ahead and change scrollbar-width
  481.      and scrollbar-height.  Otherwise, we're merely mirroring
  482.      a change made to scrollbar-width etc. so don't do anything
  483.      special. */
  484.       if (cur->emacs_frame.scrollbar_width !=
  485.       new->emacs_frame.scrollbar_width)
  486.     Fadd_spec_to_specifier
  487.       (Vscrollbar_width,
  488.        make_number (new->emacs_frame.scrollbar_width),
  489.        frame, Qnil, Qnil);
  490.       if (cur->emacs_frame.scrollbar_height !=
  491.       new->emacs_frame.scrollbar_height)
  492.     Fadd_spec_to_specifier
  493.       (Vscrollbar_height,
  494.        make_number (new->emacs_frame.scrollbar_height),
  495.        frame, Qnil, Qnil);
  496.       if (cur->emacs_frame.top_toolbar_height !=
  497.       new->emacs_frame.top_toolbar_height)
  498.     Fadd_spec_to_specifier
  499.       (Vtop_toolbar_height,
  500.        make_number (new->emacs_frame.top_toolbar_height),
  501.        frame, Qnil, Qnil);
  502.       if (cur->emacs_frame.bottom_toolbar_height !=
  503.       new->emacs_frame.bottom_toolbar_height)
  504.     Fadd_spec_to_specifier
  505.       (Vbottom_toolbar_height,
  506.        make_number (new->emacs_frame.bottom_toolbar_height),
  507.        frame, Qnil, Qnil);
  508.       if (cur->emacs_frame.left_toolbar_width !=
  509.       new->emacs_frame.left_toolbar_width)
  510.     Fadd_spec_to_specifier
  511.       (Vleft_toolbar_width,
  512.        make_number (new->emacs_frame.left_toolbar_width),
  513.        frame, Qnil, Qnil);
  514.       if (cur->emacs_frame.right_toolbar_width !=
  515.       new->emacs_frame.right_toolbar_width)
  516.     Fadd_spec_to_specifier
  517.       (Vright_toolbar_width,
  518.        make_number (new->emacs_frame.right_toolbar_width),
  519.        frame, Qnil, Qnil);
  520.     }
  521.   in_resource_setting--;
  522.  
  523.   return False;
  524.  
  525.   /* Note that if either (a) we return True, or (b) the width or
  526.      height has changed, an Expose event will be generated.  The Xt
  527.      manual says you should not return True if the width or height has
  528.      changed, because then two Expose events will be generated.
  529.  
  530.      In any case, there is no need to return True because
  531.      SET_FACE_PROPERTY(), which does the resource
  532.      setting, automatically forces a redisplay as necessary. */
  533. }
  534.  
  535. static XtGeometryResult
  536. EmacsFrameQueryGeometry (Widget widget, XtWidgetGeometry* request,
  537.               XtWidgetGeometry* result)
  538. {
  539.   EmacsFrame ew = (EmacsFrame)widget;
  540.   int mask = request->request_mode;
  541.   Dimension width, height;
  542.   Dimension ok_width, ok_height;
  543.  
  544.   /* We have a definite preference for what size we would like
  545.      to be.
  546.  
  547.      1) If a preferred size was specified for us, use it.
  548.         (This is not currently used)
  549.      2) If a proposed size was given, round it to the nearest
  550.         multiple of the default char size and return it.
  551.      3) Otherwise, take our current size and round it to the
  552.         nearest multiple of the default char size. */
  553.  
  554.   width = mask & CWWidth ? request->width : ew->core.width;
  555.   height = mask & CWHeight ? request->height : ew->core.height;
  556.   round_size_to_char (ew, width, height, &ok_width, &ok_height);
  557.   if (ew->emacs_frame.preferred_width)
  558.     ok_width = ew->emacs_frame.preferred_width;
  559.   if (ew->emacs_frame.preferred_height)
  560.     ok_height = ew->emacs_frame.preferred_height;
  561.   result->request_mode |= CWWidth | CWHeight;
  562.   result->width = ok_width;
  563.   result->height = ok_height;
  564.   if (((mask & CWWidth) && ok_width != request->width)
  565.       || ((mask & CWHeight) && ok_height != request->height))
  566.     return XtGeometryAlmost;
  567.   else
  568.     return XtGeometryYes;
  569. }
  570. /**** string-to-scrollbar-placement converter: modelled after edge-type
  571.       converter in Xaw/Form.c ****/
  572.  
  573. #define    done(address, type) \
  574. { toVal->size = sizeof(type); \
  575.     toVal->addr = (caddr_t) address; \
  576.     return; \
  577. }
  578.  
  579. /* This variable cannot be a stack variable. */
  580. static unsigned char cvt_string_scrollbar_placement;
  581.  
  582. /* ARGSUSED */
  583. static void
  584. _CvtStringToScrollBarPlacement (args, num_args, fromVal, toVal)
  585.      XrmValuePtr args;        /* unused */
  586.      Cardinal *num_args;    /* unused */
  587.      XrmValuePtr fromVal;
  588.      XrmValuePtr toVal;
  589. {
  590.   XrmQuark q;
  591.   char lowerName[1000];
  592.   
  593.   XmuCopyISOLatin1Lowered (lowerName, (char*)fromVal->addr);
  594.   q = XrmStringToQuark(lowerName);
  595.   if (q == XrmStringToQuark ("top_left"))
  596.     {
  597.       cvt_string_scrollbar_placement = XtTOP_LEFT;
  598.       done (&cvt_string_scrollbar_placement, unsigned char);
  599.     }
  600.   if (q == XrmStringToQuark ("bottom_left"))
  601.     {
  602.       cvt_string_scrollbar_placement = XtBOTTOM_LEFT;
  603.       done (&cvt_string_scrollbar_placement, unsigned char);
  604.     }
  605.   if (q == XrmStringToQuark ("top_right"))
  606.     {
  607.       cvt_string_scrollbar_placement = XtTOP_RIGHT;
  608.       done (&cvt_string_scrollbar_placement, unsigned char);
  609.     }
  610.   if (q == XrmStringToQuark ("bottom_right"))
  611.     {
  612.       cvt_string_scrollbar_placement = XtBOTTOM_RIGHT;
  613.       done (&cvt_string_scrollbar_placement, unsigned char);
  614.     }
  615.   XtStringConversionWarning (fromVal->addr, "scrollBarPlacement");
  616.   toVal->addr = NULL;
  617.   toVal->size = 0;
  618. }
  619.  
  620. static void
  621. EmacsFrameClassInitialize (void)
  622. {
  623.   XtAddConverter (XtRString, XtRScrollBarPlacement,
  624.           _CvtStringToScrollBarPlacement, NULL, 0 );
  625. }
  626.  
  627. /********************* Special entrypoints *******************/
  628.  
  629. void
  630. EmacsFrameRecomputeCellSize (Widget w)
  631. {
  632.   EmacsFrame ew = (EmacsFrame) w;
  633.   Dimension cw;
  634.   Dimension ch;
  635.  
  636.   if (! XtIsSubclass (w, emacsFrameClass))
  637.     abort ();
  638.  
  639.   get_default_char_pixel_size (ew, &cw, &ch);
  640.   if (FRAME_X_TOP_LEVEL_FRAME_P (ew->emacs_frame.frame))
  641.     x_wm_set_cell_size (FRAME_X_SHELL_WIDGET (ew->emacs_frame.frame), cw, ch);
  642. }
  643.  
  644. /* Set the size of the widget to have the number of rows and columns
  645.    specified.  This both causes the X window to change and the
  646.    internal frame structures to get modified to match. */
  647.  
  648. void
  649. EmacsFrameSetCharSize (Widget widget, int columns, int rows)
  650. {
  651.   EmacsFrame ew = (EmacsFrame) widget;
  652.   Dimension pixel_width, pixel_height;
  653.   if (columns < 3) columns = 3;  /* no way buddy */
  654.   if (rows < 1) rows = 1;
  655.  
  656.   char_to_pixel_size (ew, columns, rows, &pixel_width, &pixel_height);
  657.  
  658.   if (FRAME_X_TOP_LEVEL_FRAME_P (ew->emacs_frame.frame))
  659.     x_wm_set_variable_size (FRAME_X_SHELL_WIDGET (ew->emacs_frame.frame),
  660.                 columns, rows);
  661.  
  662.   XtVaSetValues ((Widget) ew,
  663.          XtNwidth, pixel_width,
  664.          XtNheight, pixel_height,
  665.          0);
  666. }
  667.